<style lang="less" scoped>
    @import '../../styles/common.less';
    @import '../../styles/loading.less';
    @import 'assess.less';
</style>

<template>
    <div>
       <Row style="font-size: 15px;">
            活动名称：<Input v-model="queryCon.ordername" clearable style="width: 15%"></Input>
            <span @click="loadList"><Button type="primary" icon="android-search">查询</Button></span>
        </Row>
        <div class="main-table">
            <Table border :columns="columns" :data="data"></Table>
        </div>
        <div class="pagination">
            <Page :total="total" size="small" :page-size="pageSize" :current.sync="pageIndex" @on-change="loadList" show-total show-elevator></Page>
        </div>
        <Modal
                v-model="viewModalVisible"
                title="评价信息"
                @on-ok="viewModalVisible = false"
                @on-cancel="viewModalVisible = false"
                width="45%">
            <Form :model="formData" :label-width="180">
                <Row>
                    <Col span="16">
                    <FormItem label="活动名称">
                        <div class="conts">{{formData.ordername}}</div>
                    </FormItem>
                    </Col>
                </Row>
                <Row>
                    <Col span="16">
                    <FormItem label="评价人">
                        <div class="conts">{{formData.orderuser}}</div>
                    </FormItem>
                    </Col>
                </Row>
                <Row>
                    <Col span="16">
                    <FormItem label="评价星级">
                        <Rate disabled v-model="formData.level"></Rate>
                    </FormItem>
                    </Col>
                </Row>
                <Row>
                    <Col span="16">
                    <FormItem label="评价时间">
                        <div class="conts">{{formData.time}}</div>
                    </FormItem>
                    </Col>
                </Row>
                <Row>
                    <Col span="16">
                    <FormItem label="评语">
                        <div class="conts">{{formData.comment}}</div>
                    </FormItem>
                    </Col>
                </Row>
            </Form>
        </Modal>
    </div>
</template>

<script>
    import util from '@/libs/util';
    export default {
        name: 'exportable-table',
        data () {
            return {
                columns: [{
                    title: '序号',
                    key: 'rownum',
                    width: 60,
                    align: 'center'
                }, {
                    title: '活动名称',
                    key: 'ordername',
                    render: (h, params) => {
                        let texts = params.row.order.activity.name;
                        return h('div',{},texts)
                    }
                },{
                    title: '评价人',
                    key: 'orderuser',
                    render: (h, params) => {
                        let texts = params.row.order.user.name;
                        return h('div',{},texts)
                    }
                },{
                    title: '评价时间',
                    key: 'time'
                },   {
                    title: '操作',
                    key: 'action',
                    width: 300,
                    align: 'center',
                    render: (h, params) => {
                        let isShow = 'none';
                        if(params.row.releases == 'NO'){
                            isShow = 'inline';
                        }  return h('div', [
                            h('Button', {
                                props: {
                                    type: 'primary',
                                    size: 'small'
                                },
                                style: {
                                    marginRight: '5px'
                                },
                                on: {
                                    click: () => {
                                        this.detail(params.row);
                                    }
                                }
                            }, '详情'),
                            h('Button', {
                                props: {
                                    type: 'error',
                                    size: 'small'
                                },
                                on: {
                                    click: () => {
                                        this.delete(params.row.id)
                                    }
                                }
                            }, '删除')
                        ]);
                    }
                }],
                data: [],
                formData: {},
                viewModalVisible: false,
                saveModalVisible: false,
                priceModalVisible: false,
                isSelect:true,
                isInput:false,

                total: 0,
                pageIndex: 1,
                pageSize: 10,
                queryCon:{
                    ordername:'',
                    time:'',
                    level:'',
                    id:'',
                    comment:'',
                    orderId:'',
                    order:''
                },
                id:''
            };
        },
        mounted() {
            this.loadList();
        },
        methods: {
            loadList() {
                util.ajax.post('/busine/assess/list', util.toFormData({
                    page: this.pageIndex,
                    size: this.pageSize,
                    ordername:this.queryCon.ordername,
                })).then(res => {
                    var lists = res.data.data.list;
                    this.data = lists;
                    for (var i = 0; i < lists.length; i++) {
                        lists[i]['time'] = this.getDate(lists[i].time);
                    }
                    this.level=res.data.data.level;
                    this.data = res.data.data.list;
                    this.total = res.data.data.total;
                });
            },
            detail(obj) {
                let _this = this;
                util.ajax.post( '/busine/assess/detail', util.toFormData({
                    id: obj.id
                })).then(res => {
                    if (res.data.data) {
                        var li = res.data.data;
                            if (li.order) {
                                li["ordername"] = obj.order.activity.name;
                            }
                            if (li.order) {
                                li["orderuser"] = obj.order.user.name;
                            }
                            li['time'] = this.getDate(li.time);
                        _this.formData = res.data.data;
                        _this.viewModalVisible = true;
                    } else {
                        _this.$Modal.error({
                            title: '警告',
                            content: '出错了'
                        });
                    }
                });
            },
            delete(id) {
                this.$Modal.confirm({
                    title: '提示',
                    content: '<p>确定删除？</p>',
                    onOk: () => {
                        util.ajax.post('/busine/assess/delete', util.toFormData({
                            id: id
                        })).then(res => {
                            if (res.data.message === 'SUCCESS') {
                                this.$Message.success('删除成功！');
                                this.loadList();
                            }
                        });
                    },
                    onCancel: () => {
                    }
                });
            },
            getDate(data) {
                let myDate;

                if (data instanceof Date){
                    myDate = data;
                } else if (typeof(data) == 'number') {
                    myDate = new Date(data);
                } else {
                    return data;
                }

                let Y = myDate.getFullYear(),
                    M = myDate.getMonth() + 1,
                    D = myDate.getDate(),
                    H = myDate.getHours(),
                    Min = myDate.getMinutes(),
                    S = myDate.getSeconds();

                if (M < 10) {
                    M = '0' + M;
                }
                if (D < 10) {
                    D = '0' + D;
                }
                if (H < 10) {
                    H = '0' + H;
                }
                if (Min < 10) {
                    Min = '0' + Min;
                }
                if (S < 10) {
                    S = '0' + S;
                }
                return Y + '-' + M + '-' + D + '  ' + H + ':' + Min + ':' + S ;
            },refresh(){
                this.queryCon = {
                    time:'',
                    level:'',
                    id:'',
                    comment:'',
                    orderId:'',
                    order:'',
                    ordername:'',
                };
                this.loadList();
            },
        }
    };
</script>
